package it.sandler.android;

import it.sandler.android.database.SandlerDatabase;
import it.sandler.android.database.SandlerDatabase.Recursion;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;

public class SandlerDBActivity extends Activity {
	
	/** Called when the activity is first created. */
	@SuppressWarnings("unchecked")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		SandlerDatabase db = new SandlerDatabase(this, "tasks", 10,
				TaskList.class, Task.class);

		ArrayList<TaskList> userLists = db.findAll(TaskList.class);
		if (userLists.size() == 0) {
			// default tasklist
			TaskList taskList = new TaskList();
			taskList.setName("Your task list");
			Task task1 = new Task("Very first task");
			Task task2 = new Task("Second sample task");
			taskList.addTask(task1, task2);

			// store tasklist and its tasks in db
			db.setRecursion(Recursion.FULL);
			db.save(taskList);

		}

		// do some UI stuff
	}
}